package com.adv.ems.model.vo;

import cn.hutool.core.date.DateUtil;
import com.adv.ems.db.entity.SystemWarningDO;
import com.adv.ems.enums.CollectPointWarningTypeEnum;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class WarningListVO {
    private List<Info> list;
    private Boolean hasMore;

    public WarningListVO() {
        this.list = new ArrayList<Info>();
    }

    @Data
    public static class Info {
        private Long id;
        private String typeName;
        private String content;
        private String value;
        private String objName;
        private String time;
        private String handleStatus;
        private Boolean done;

        public Info(SystemWarningDO warning) {
            this.id = warning.getId();
            if (CollectPointWarningTypeEnum.EXCEPTION_DATA.name().equals(warning.getType())) {
                this.typeName = "数据异常告警";
            }else if (CollectPointWarningTypeEnum.OFFLINE.name().equals(warning.getType())) {
                this.typeName = "设备掉线告警";
            }else if (CollectPointWarningTypeEnum.SAFE_LOW.name().equals(warning.getType())) {
                this.typeName = "低于安全值告警";
            }else if (CollectPointWarningTypeEnum.SAFE_UP.name().equals(warning.getType())) {
                this.typeName = "高于安全值告警";
            }
            this.content = warning.getMsg();
            this.value = warning.getValue();
            this.objName = warning.getObjClsName();
            this.time = DateUtil.formatDateTime(warning.getUpdateTime());
            if ("READED".equals(warning.getState())) {
                this.done = true;
                this.handleStatus = "已处理";
            }else {
                this.done = false;
                this.handleStatus = "未处理";
            }
        }
    }
}
